
$(document).ready(function(){
var mySite = (function(){
    //form.find( 'input[name="nom"]' ).val()
    $form = $('#top-content form');
    $registerLoginSwap = $('#register-login-swap');
    
    return {
	registerLoginSwap : function(){
	    $registerLoginSwap.click(function(){
		if ($(this).hasClass('ask-login')){
		    $(this).removeClass('ask-login');
		    $(this).addClass('ask-register');
		    $(this).html('Register');
		    
		    $form.find('input[type="submit"]' ).val('Login');
		    $form.attr('action', sitepath + 'home/login');
		}
		else if ($(this).hasClass('ask-register')){
		    $(this).removeClass('ask-register');
		    $(this).addClass('ask-login');
		    $(this).html('Login');
		    
		    $form.find( 'input[type="submit"]' ).val('Register');
		    $form.attr("action", sitepath + 'home/register');
		}
	    });
	},
	manageLogin : function(){
	    if (!login_status)
	    {
		$('.settings .openclose').click(function(){
		    var target = $(this).parent().parent('.settings');
		    if(target.is('.display_switch')){
		    	target.animate({top: "-78"}, function(){
			    target.removeClass('display_switch').addClass('display_settings_false');
			});
		    }
                    else {
		    	target.animate({top: "0"}, function(){
			    target.removeClass('display_settings_false').addClass('display_switch');
			});
		    }
		});
		if (show_login)
		{
		    $('.settings .openclose').trigger('click');
		}
	    }
	    else
	    {
		$('.settings .openclose').click(function(){
		    window.location.href = sitepath + 'home/logout'
		});

	    }
	}
    };
}());

    mySite.registerLoginSwap();
    mySite.manageLogin();
});